tools: Fix xenstored build error by checking vasprintf() return code.
authorKeir Fraser <keir@xensource.com>
Sun, 10 Jun 2007 18:58:22 +0000 (19:58 +0100)
committerKeir Fraser <keir@xensource.com>
Sun, 10 Jun 2007 18:58:22 +0000 (19:58 +0100)
Signed-off-by: Charles Coffing <ccoffing@novell.com>
tools/xenstore/utils.c

index 6655777bcd402460538c1a70e7fcaf99db376eff..16f87cdc05b07da311aa020f58193dedf4178ec7 100644 (file)
@@ -27,33 +27,38 @@ void xprintf(const char *fmt, ...)
 void barf(const char *fmt, ...)
 {
        char *str;
+       int bytes;
        va_list arglist;
 
        xprintf("FATAL: ");
 
        va_start(arglist, fmt);
-       vasprintf(&str, fmt, arglist);
+       bytes = vasprintf(&str, fmt, arglist);
        va_end(arglist);
 
-       xprintf("%s\n", str);
-       free(str);
+       if (bytes >= 0) {
+               xprintf("%s\n", str);
+               free(str);
+       }
        exit(1);
 }
 
 void barf_perror(const char *fmt, ...)
 {
        char *str;
-       int err = errno;
+       int bytes, err = errno;
        va_list arglist;
 
        xprintf("FATAL: ");
 
        va_start(arglist, fmt);
-       vasprintf(&str, fmt, arglist);
+       bytes = vasprintf(&str, fmt, arglist);
        va_end(arglist);
 
-       xprintf("%s: %s\n", str, strerror(err));
-       free(str);
+       if (bytes >= 0) {
+               xprintf("%s: %s\n", str, strerror(err));
+               free(str);
+       }
        exit(1);
 }